from __future__ import division
from operator import itemgetter, attrgetter
import os
import sys
import math

LOWER_BOUND_FOR_RANGE1 = 1
UPPER_BOUND_FOR_RANGE1 = 100
UPPER_BOUND_FOR_RANGE2 = 5000
UPPER_BOUND_FOR_RANGE3 = 80000
UPPER_BOUND_FOR_RANGE4 = 600000
UPPER_BOUND_FOR_RANGE5 = 25205179

freqClassLabelList = ["N/A","VR","NF","M","F","VF"]
currentRangesUpperBoundsList = [1,100,5000,80000,600000,25205179]
smallBucketsForTheSpecifcRangesTryingToBreakList = [0,5,43,256,500,196]

outputFileName = "/data3/obukai/the_new_trip_of_feature_generation/gov2ClearYourMindAndDoItAgain/probabilityDistributionEstimationByProf/fourSetOfQueriesByProf20130410/smallBucketsEquallizationMethodByProf20130411/smallBucketsRangesForQueryTermOverGov2Dataset"
outputFileHanlder = open(outputFileName,"w")

for i in range(1,len(currentRangesUpperBoundsList)):
    totalGapForThisRange = currentRangesUpperBoundsList[i] - currentRangesUpperBoundsList[i-1]
    numOfSmallBucketsInThisRange = smallBucketsForTheSpecifcRangesTryingToBreakList[i]
    rangeGapForTheSmallBucket = int(totalGapForThisRange / numOfSmallBucketsInThisRange)
    print freqClassLabelList[i],"[",currentRangesUpperBoundsList[i-1],",",currentRangesUpperBoundsList[i],")",totalGapForThisRange
    print "numOfSmallBucketsInThisRange:",numOfSmallBucketsInThisRange
    print "rangeGapForTheSmallBucket:",rangeGapForTheSmallBucket
    
    for j in range(1,numOfSmallBucketsInThisRange):
        currentSmallRangeLowerBound = currentRangesUpperBoundsList[i-1] + (j-1) * rangeGapForTheSmallBucket
        currentSmallRangeUpperBound = currentRangesUpperBoundsList[i-1] + j * rangeGapForTheSmallBucket
        print "--->",freqClassLabelList[i],"sub",j,":","[",currentSmallRangeLowerBound,",",currentSmallRangeUpperBound,")"
        outputFileHanlder.write(str(freqClassLabelList[i]) + " " + str(j) + " " + str(currentSmallRangeLowerBound) + " " + str(currentSmallRangeUpperBound) + "\n")
    # final range
    j += 1
    currentSmallRangeLowerBound = currentRangesUpperBoundsList[i-1] + (numOfSmallBucketsInThisRange-1) * rangeGapForTheSmallBucket
    currentSmallRangeUpperBound = currentRangesUpperBoundsList[i]
    print "--->",freqClassLabelList[i],"sub",j,":","[",currentSmallRangeLowerBound,",",currentSmallRangeUpperBound,")"
    outputFileHanlder.write(str(freqClassLabelList[i]) + " " + str(j) + " " + str(currentSmallRangeLowerBound) + " " + str(currentSmallRangeUpperBound) + "\n")

outputFileHanlder.close()
    
    
    
    
    
    
    